<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="100px"
    >
      <el-form-item label="单据编号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入单据编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="orderList"
    >
      <el-table-column
        label="单据编号"
        align="center"
        prop="orderNumber"
      />
      <el-table-column
        label="上游单据编号"
        align="center"
        prop="parentOrderNumber"
      />
      <el-table-column label="单据类型" align="center" prop="typeStr" />
      <el-table-column label="单据状态" align="center" prop="status">
        <template slot-scope="scope">
          <div v-if="scope.row.status === '0'">未审核</div>
          <div v-if="scope.row.status === '1'">已审核</div>
        </template>
      </el-table-column>
      <el-table-column label="企业" align="center" prop="enterpriseName" />
      <el-table-column
        label="单据时间"
        align="center"
        prop="orderTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="物料编码"
        align="center"
        prop="code"
      />
      <el-table-column
        label="物料名称"
        align="center"
        prop="name"
      />
      <el-table-column label="数量" align="center" prop="num" />
      <el-table-column label="单价" align="center" prop="price" />
      <el-table-column label="供应商" align="center" prop="supplierName" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  cgrkOrder,
} from "@/api/system/order";

export default {
  name: "CgrkcxOrder",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 单据表格数据
      orderList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        type: "6",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询单据列表 */
    getList() {
      this.loading = true;
      cgrkOrder(this.queryParams).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
